home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / GetDragHiliteColor / Source / GetDragHilite.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-17  |  3.4 KB  |  118 lines  |  [TEXT/CWIE]

  1. #include <Windows.h>
  2. #include <QuickDraw.h>
  3.  
  4. #define wTitleBarColor    4
  5. #define wTingeLight        11
  6. #define wTingeDark        12
  7.  
  8. unsigned short BlendValues(short lightValue, short darkValue);
  9. void SetupDragHiliteColor(WindowPtr targetWindow);
  10.  
  11.  
  12. /*-------------------------------------------------------------------------------------
  13.  
  14. BlendValues
  15.  
  16.     Blend two color values by 27%.  Be careful of overflow when multiplying
  17.     a negative number.  Output should be light + 27% of difference between light
  18.     and dark.
  19.  
  20. */
  21. unsigned short BlendValues(short lightValue, short darkValue)
  22. {
  23.     register short blender;
  24.  
  25.     blender = darkValue - lightValue;
  26.  
  27.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  28.         blender = -blender;                        // flip if subtraction would overflow
  29.  
  30.     blender = (unsigned short)((unsigned short)blender * .27);
  31.                                                 // 27% percent multiply
  32.  
  33.     if ((unsigned long)lightValue > (unsigned long)darkValue)
  34.         blender = -blender;                        // flip it back if it was flipped the
  35.                                                 // first time.
  36.  
  37.     return ((unsigned short)(lightValue + blender));
  38. }
  39.  
  40.  
  41. /*-------------------------------------------------------------------------------------
  42.  
  43. SetupDragHiliteColor
  44.  
  45.     Set the fore color to the color used by the Drag Manager to hilite regions.
  46.     
  47. */
  48. void SetupDragHiliteColor(WindowPtr targetWindow)
  49. {
  50.     RGBColor windowRGB, lightRGB, darkRGB;
  51.     AuxWinHandle auxHandle;                        // the default AuxWindow data
  52.     CTabHandle winColorTable;                        // the window color table
  53.     short i, j;                                    // for our color table search
  54.  
  55.     windowRGB.red = 0x8000;                        // Default to 50% gray.
  56.     windowRGB.green = 0x8000;
  57.     windowRGB.blue = 0x8000;
  58.  
  59.     // If we're using a window which uses System 7's 3D colors
  60.     // then set the hilite color to a tinge for that window.
  61.  
  62.     GetAuxWin(targetWindow, &auxHandle);
  63.  
  64.     // do we have an aux window handle ?
  65.     if (auxHandle != nil) {
  66.         winColorTable = (**auxHandle).awCTable;
  67.  
  68.         // do we have a system 7 sized window color table?
  69.         if ((**winColorTable).ctSize > wTitleBarColor) {
  70.             
  71.             // yes, now search for the tinge color, start at the end
  72.             // because our tinge colors are usually last in the list.
  73.             for (i = (**winColorTable).ctSize; i > 0; i--) {
  74.                 if ((**winColorTable).ctTable[i].value == wTingeLight) {
  75.  
  76.                     // light tinge found, set the window color to it
  77.                     // in case we can't find the dark tinge.
  78.                     lightRGB = (**winColorTable).ctTable[i].rgb;
  79.  
  80.                     windowRGB.red = lightRGB.red;
  81.                     windowRGB.green = lightRGB.green;
  82.                     windowRGB.blue = lightRGB.blue;
  83.  
  84.                     // we now need the wTingeDark entry to perform a blend.
  85.                     // again, search from the end
  86.                     for (j = (**winColorTable).ctSize; j > 0; j--)
  87.                         if ((**winColorTable).ctTable[j].value == wTingeDark) {
  88.                             // dark tinge found.  now do the blend
  89.  
  90.                             darkRGB = (**winColorTable).ctTable[j].rgb;
  91.  
  92.                             windowRGB.red = BlendValues((short)lightRGB.red, (short)darkRGB.red);
  93.                             windowRGB.green = BlendValues((short)lightRGB.green, (short)darkRGB.green);
  94.                             windowRGB.blue = BlendValues((short)lightRGB.blue, (short)darkRGB.blue);
  95.  
  96.                             // if the Color control panel was set to "Black and White", it makes the
  97.                             // tinge colors black and black.  Use gray in this case
  98.  
  99.                             if ((windowRGB.red | windowRGB.green | windowRGB.blue) == 0) {
  100.                                 windowRGB.red = 0x8000;
  101.                                 windowRGB.green = 0x8000;
  102.                                 windowRGB.blue = 0x8000;
  103.                             }
  104.  
  105.                             j = 0;                // bail from inner loop
  106.                         }
  107.  
  108.                     i = 0;                        // bail from outer loop
  109.                 }
  110.             }
  111.         }
  112.     }
  113.  
  114.     RGBForeColor(&windowRGB);        // finally, set it
  115. }
  116.  
  117.  
  118.